import csv


class CSVConsumer(object):

    def __init__(self):
        self.source = []

    def consume(self, file):
        with open(file) as csv_file:
            csv_reader = csv.DictReader(csv_file)
            for row in csv_reader:
                self.source.append(row)

    def get_loadbalancer_ids(self):
        return [
            res["uuid"]
            for res in self.source
            if res['resource type']=="loadbalancer"
        ]

    def get_listener_ids(self):
        return [
            res["uuid"]
            for res in self.source
            if res['resource type']=="listener"
        ]

    def get_pool_ids(self):
        return [
            res["uuid"]
            for res in self.source
            if res['resource type']=="pool"
        ]

    def get_member_ids(self):
        return [
            res["uuid"]
            for res in self.source
            if res['resource type']=="member"
        ]

    def get_healthmonitor_ids(self):
        return [
            res["uuid"]
            for res in self.source
            if res['resource type']=="healthmonitor"
        ]

    def get_l7policy_ids(self):
        return [
            res["uuid"]
            for res in self.source
            if res['resource type']=="l7policy"
        ]

    def get_l7rule_ids(self):
        return [
            res["uuid"]
            for res in self.source
            if res['resource type']=="l7rule"
        ]

def get_consumer(tp, *args, **kwargs):
    consumer = None

    if tp == "csv":
        file = kwargs.get("csv_file")
        consumer = CSVConsumer()
        consumer.consume(file)

    return consumer
